trigger AutoSetRecordType on NationalAttendee__c (before insert) {
        list<recordtype> rlist=new list<recordtype>();
        list<id> hcpeduid=new list<id>();
        id national;
        id saloon;
        id ps;
        id hcpnational;
        id hcpsaloon;
        id hcpps;
        rlist=[select id,developername from recordtype where (sobjecttype=:'nationalattendee__c' and (developername=:'NationalHCPEducationActivity' or developername=:'saloon' or developername=:'pocketsession' )) 
                 or (sobjecttype=:'hcpeducation__c' and (developername=:'nationalHCPEducation' or developername=:'SalonPlan' or developername=:'PocketSession' ))];
        
        for(recordtype rt:rlist){
            if(rt.developername=='NationalHCPEducationActivity'){
                national=rt.id;
            }
            if(rt.developername=='saloon'){
                saloon=rt.id;
            }
            if(rt.developername=='pocketsession'){
                ps=rt.id;
            }
            if(rt.developername=='nationalHCPEducation'){
                hcpnational=rt.id;
            }
            if(rt.developername=='SalonPlan'){
                hcpsaloon=rt.id;
            }
            if(rt.developername=='PocketSession'){
                hcpps=rt.id;
            }
        }
        
        for(NationalAttendee__c na:trigger.new){
            hcpeduid.add(na.hcpeducation__c);
        }
        list<Hcpeducation__c> hcpl=[select id,recordtypeid from hcpeducation__c where id in :hcpeduid];
        
        for(hcpeducation__c h:hcpl){
            for(NationalAttendee__c n:trigger.new){
              if(h.id==n.hcpeducation__c){
                if(h.recordtypeid==hcpnational){
                    n.recordtypeid=national;
                }
                if(h.recordtypeid==hcpsaloon){
                    n.recordtypeid=saloon;
                }
                if(h.recordtypeid==hcpps){
                    n.recordtypeid=ps;
                }
              }
            }
        }
        //自动设置出席者的大区和城市名单
        if(trigger.new[0].recordtypeid==national){
        list<joinpeople__c> jpl=new list<joinpeople__c>();
        jpl=[select id,CityNameList__c,NationalHCPEducation__c,regionNameListId__c from joinpeople__c where CityNameList__r.regionNameList__r.HCPEducation__c=:trigger.new[0].hcpeducation__c and User__c=:userinfo.getuserid()];
        
        if(jpl.size()>0){
           joinpeople__c jp=jpl[0];
        
        for(nationalattendee__c n:trigger.new){
            n.CityNameLists__c=jp.CityNameList__c;
            n.regionnamelist__c=jp.regionNameListId__c;
        }
        }
        }
}